<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="账号密码">
        <el-input v-model="im.password"></el-input>
      </el-form-item>
      <el-form-item label="账号类型">
        <el-select v-model="im.flag" placeholder="请选择付款方式">
          <el-option
            v-for="item in imTypes"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即充值</el-button>
        <el-button  @click="close()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>

</template>

<script>
import { getDictByType } from '@/api/dict'
import { addIm } from '@/api/customerIm'

export default {
  name: 'CustomerImAdd',
  props:{
    id: {
      type: Number,
      default: null
    }
  }
  ,
  data(){
    return{
      im:{},
      imTypes:[],

    }
  },
  methods:{
    getImTypeDict(){
      getDictByType("im_type").then(res=>{
        this.imTypes=res;
      })
    }
    ,
    close(){
      this.$emit("close");
    },
    onSubmit(){
      addIm(this.im).then(res=>{
        if (res==0){
          this.$message.error('账号新增失败!');
        }else {
          this.$message({
            message: '账号新增成功!',
            type: 'success'
          });
        }
      })
    }
  },
  mounted() {
    this.im.customerId=this.id;
    this.getImTypeDict();
  }
}
</script>

<style scoped>

</style>
